//	ID : pallab81
// 	PROG : 11517
// 	LANG : C++
// 	2011-07-26-20.46.43 Tuesday
//
// 	"I have not failed, I have just found 10000 ways that won't work.
//


#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>

#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>

using namespace std;

#define fo(i,ed) for(int i = 0 ; i < ed ; ++i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )

int money;
int n;
vector<int> w;
inline void read() {
    cin>>money>>n;
    w.assign(n,0);
    fo(i,n) {
        cin>>w[i];
    }
}
vector<int>  cando;
inline void proc() {
    cando.assign(70000,-1);
    cando[0]=0;
    for(int i=0;i<n;++i){
        for(int j=20000; j>=0;--j){
            if(cando[j]!=-1){
                if( cando[j+w[i]]==-1){
                    cando[j+w[i]] = cando[j]+1;
                }
                else{
                    cando[j+w[i]] = min( cando[j+w[i]], cando[j]+1);
                }
            }
        }
    }

    for(int i=money;i<=20000;++i){
        if(cando[i]!=-1){
            cout<<i<<" "<<cando[i]<<"\n";
            return ;
        }
    }

}


int main() {
#ifndef ONLINE_JUDGE
    freopen("in.txt","rt",stdin);
#endif
    int cases;
    for( cin>>cases; cases; --cases) {
        read();
        proc();
    }

    return 0;
}


